// 登录页面JS
function loginID() {
    var loginID = document.getElementById("docID");
    loginIDValue = loginID.value;
    // 字符串中包含大写或小写字母,长度不小于8位且必须包含数字
    if (loginIDValue.replace(/\s+/g, "") == "") {
        alert("账号格式错误！");
        loginID.classList.add("wrong");
        return false;
    }
    else {
        loginID.classList.remove("wrong");
        return true;
    }
}


function loginPwd() {
    var password = document.getElementById("password");
    passwordValue = password.value;
    // 字符串中是否同时包含字母、数字、特殊符号且长度大于等于8
    var regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$/;
    if (!regex.test(passwordValue) || passwordValue == "") {
        alert("密码格式错误！");
        password.classList.add("wrong");
        return false;
    }
    else {
        password.classList.remove("wrong");
        return true;
    }
}

function loginCheck(){
    if(loginID() && loginPwd()){
        return true;
    }
    else{
        return false;
    }
}


// 重置密码JS
function resetID() {
    var resetID = document.getElementById("resetdocID");
    resetIDValue = resetID.value;
    if (resetIDValue.replace(/\s+/g, "") == "") {
        alert("账号格式错误！");
        resetID.classList.add("wrong");
        return false;
    }
    else {
        resetID.classList.remove("wrong");
        return true;
    }
}


function resetPwd() {
    var resetPwd = document.getElementById("resetpassword");
    resetPwdValue = resetPwd.value;
    // 字符串中是否同时包含字母、数字、特殊符号且长度大于等于8
    var regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$/;
    if (!regex.test(resetPwdValue) || resetPwdValue == "") {
        alert("密码格式错误！");
        resetPwd.classList.add("wrong");
        return false;
    }
    else {
        resetPwd.classList.remove("wrong");
        return true;
    }
}

function resetRePwd() {
    var resetpassword = document.getElementById("resetpassword");
    var resetrePassword = document.getElementById("resetrePassword");
    if (resetPwd()) {
        if (resetrePassword.value.replace(/\s+/g, '') != resetpassword.value.replace(/\s+/g, '')) {
            resetrePassword.classList.add("wrong");
            alert("两次密码不一致！");
            return false;
        } else {
            resetrePassword.classList.remove("wrong");
            return true;
        }
    }
}

function resetKey(){
    var resetKey = document.getElementById("resetkey");
    // 只包含大小写字母的8位长度字符串
    var regex = /^(?=.*[a-zA-Z])[a-zA-Z]{8}$/;
    if (!regex.test(resetKey.value) || resetKey.value == "") {
        alert("密钥格式错误！");
        resetKey.classList.add("wrong");
        return false;
    }else{
        resetKey.classList.remove("wrong");
        return true;
    }
}

function resetForm(){
    if(resetPwd() && resetRePwd() && resetKey()){
        return true;
    }else{
        return false;
    }
}